<template>
  <div class="content">
    <div class="reporting-main">
      <div class="hd">
        <my-progress
          :data="auditStep"
          @_click="updateAudit('0')"
          v-if="!isShowGiveup"
        ></my-progress>
      </div>
      <div class="bd">
        <!-- 放弃就读水印 -->
        <div class="giveup" v-if="isShowGiveup">
          <img :src="require('../assets//images/pic_fq.png')" alt="" />
        </div>
        <div v-if="isShowStudTips" class="notice-box">
          {{ studTips.studTips }}
        </div>
        <!-- 报名信息 -->
        <div class="result-list">
          <div class="result-list-hd">
            <h3 class="title">报名信息</h3>
            <div
              v-if="isShowEditBtn"
              class="btn-link"
              @click="gotoEdit('selectgrade')"
            >
              再次修改
            </div>
          </div>
          <div class="result-list-bd">
            <van-cell-group class="van-cell__title-left">
              <van-cell title="报名号" :value="studentInfo.regId" />
              <van-cell title="选择年级" :value="studentInfo.gradeName" />
              <van-cell
                title="报名时间"
                :value="formatDateTime('YY-MM-dd', studentInfo.regDate)"
              />
              <van-cell title="是否捆绑派位" :value="studentInfo.isBindName" />
              <van-cell
                class="fle"
                title="被捆绑学生身份证号"
                :value="studentInfo.bindIdno ? 'studentInfo.bindIdno' : '----'"
              />
              <van-cell
                v-if="studentInfo.gradeName != '一年级'"
                title="原就读学校"
                :value="studentInfo.lastSchool"
              />
              <van-cell
                v-if="studentInfo.gradeName != '一年级'"
                title="学籍号"
                :value="studentInfo.studentNo"
              />
            </van-cell-group>
          </div>
        </div>
        <!-- 基本信息 -->
        <div class="result-list">
          <div class="result-list-hd">
            <h3 class="title">基本信息</h3>
            <div
              v-if="isShowEditBtn"
              class="btn-link"
              @click="gotoEdit('basicinfo')"
            >
              再次修改
            </div>
          </div>
          <!-- 学生信息 -->
          <div class="result-list-bd">
            <div class="list-bd-title"><h3>学生信息</h3></div>
            <van-cell-group class="van-cell__title-left">
              <van-cell title="入学类型" :value="studentInfo.regTypeName" />
              <van-cell title="有无户口" :value="studentInfo.ogStateName" />
              <van-cell title="户籍类型" :value="studentInfo.ogType" />
              <van-cell title="学生姓名" :value="studentInfo.name" />
              <van-cell title="性别" :value="studentInfo.gender" />
              <van-cell
                :title="stuList.regType == 'reg10' ? '证件号' : '身份证号'"
                :value="studentInfo.idno"
              />
              <van-cell
                title="出生日期"
                :value="formatDateTime('YY-MM-dd', studentInfo.birth)"
              />
              <van-cell title="民族" :value="studentInfo.nation" />
              <van-cell title="健康状态" :value="studentInfo.healthType" />
              <van-cell title="手机号" :value="studentInfo.phone" />
              <van-field
                class="van-cell-input_right"
                label="登录密码"
                right-icon="yanjing"
                v-model="studentInfo.pwd"
                name="pwd"
                readonly
                type="password"
                v-if="!isPwd"
              >
                <van-icon
                  class="iconfont iconyanjing"
                  class-prefix="icon"
                  slot="right-icon"
                  name="yanjing"
                  @click="showPwd"
                ></van-icon>
              </van-field>
              <van-field
                v-else
                class="van-cell-input_right"
                label="登录密码"
                right-icon="yanjing"
                v-model="studentInfo.pwd"
                name="pwd"
                readonly
                type="text"
              >
                <van-icon
                  class="iconfont iconyanjing"
                  class-prefix="icon"
                  slot="right-icon"
                  name="yanjing"
                  @click="showPwd"
                ></van-icon>
              </van-field>
            </van-cell-group>
          </div>
          <!-- 入学信息 -->
          <div class="result-list-bd">
            <div class="list-bd-title"><h3>入学信息</h3></div>
            <van-cell-group class="van-cell__title-left">
              <van-cell
                class="fle"
                title="实际居住产权类型"
                :value="studentInfo.houseType"
              />
              <van-cell
                title="当前居住地址"
                v-if="stuList.regType == 'reg1'"
                :value="studentInfo.origPlace"
              ></van-cell>
              <van-cell
                v-else
                title="当前居住地址"
                :value="studentInfo.regionPlace"
              ></van-cell>
              <van-cell
                title="户籍地址"
                :value="studentInfo.origPlace"
                v-if="stuList.regType == 'reg2'"
              />
              <van-cell
                title="户籍地址"
                :value="studentInfo.origPlace"
                v-else-if="stuList.regType == 'reg9'"
              />
              <van-cell
                title="户籍地址"
                :value="studentInfo.foreignAddress"
                v-else-if="stuList.regType == 'reg10'"
              />
              <van-cell
                title="户籍地址"
                :value="studentInfo.regionPlace"
                v-else
              />

              <van-cell
                v-if="studentInfo.oilType"
                title="石油系统子女"
                :value="studentInfo.oilType"
              />
              <van-cell
                v-if="studentInfo.oilType"
                title="石油学校选择"
                :value="studentInfo.oilSchoolName"
              />
              <van-row v-if="stuList.regType == 'reg9'">
                <van-cell
                  title="意向学校1"
                  :value="studentInfo.wishSchoolName1"
                />
                <van-cell
                  title="意向学校2"
                  :value="studentInfo.wishSchoolName2"
                />
                <van-cell
                  title="意向学校3"
                  :value="studentInfo.wishSchoolName3"
                />
                <van-cell title="监护人工作单位" :value="studentInfo.parWork" />
                <van-cell
                  title="工作单位电话"
                  :value="studentInfo.parWorkTel"
                />
              </van-row>
            </van-cell-group>
          </div>
          <!-- 监护人信息 -->
          <div class="result-list-bd">
            <div class="list-bd-title"><h3>监护人信息</h3></div>
            <van-cell-group class="van-cell__title-left">
              <van-cell title="监护人1姓名" :value="studentInfo.parName" />
              <van-cell
                :title="stuList.regType == 'reg10' ? '证件号' : '身份证号'"
                :value="studentInfo.parIdno"
              />
              <van-cell title="手机号码" :value="studentInfo.parPhone" />
              <van-cell title="与学生关系" :value="studentInfo.parRlat" />
              <van-cell
                v-if="studentInfo.parName2"
                title="监护人2姓名"
                :value="studentInfo.parName2"
              />
              <van-cell
                v-if="studentInfo.parIdno2"
                :title="stuList.regType == 'reg10' ? '证件号' : '身份证号'"
                :value="studentInfo.parIdno2"
              />
              <van-cell
                v-if="studentInfo.parPhone2"
                title="手机号码"
                :value="studentInfo.parPhone2"
              />
              <van-cell
                v-if="studentInfo.parRlat2"
                title="与学生关系"
                :value="studentInfo.parRlat2"
              />
            </van-cell-group>
          </div>
        </div>
        <!-- 佐证资料 -->
        <div class="result-list">
          <div class="result-list-hd">
            <h3 class="title">佐证资料<span>（点击查看大图）</span></h3>
            <div
              v-if="isShowEditBtn"
              class="btn-link"
              @click="gotoEdit('signup')"
            >
              再次修改
            </div>
          </div>
          <div class="result-list-bd fileList-box">
            <van-uploader
              :class="{ hid: !isSlider }"
              v-model="fileList"
              :max-count="fileList.length"
            />
            <div
              class="slider"
              v-if="fileList.length > 3"
              @click="isSlider = !isSlider"
            >
              点击查看更多
              <van-icon
                name="arrow-down"
                v-if="!isSlider && fileList.length > 3"
              />
              <van-icon name="arrow-up" v-else />
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="footer-btn" v-if="!isShowGiveup">
      <van-button
        block
        plain
        type="info"
        @click="updateAudit('F')"
        v-if="auditStep.giveUpIsShow == '1'"
        >放弃就读</van-button
      >
    </div>
  </div>
</template>
<script>
import { Toast, Dialog } from "vant";
import MyProgress from "../components/Progress";
import { formatDate } from "../utils/util";
import fetches from "../utils/request";
import localDb from "../utils/localDb";
import { getVerify } from "../utils/api";
const { defaultHost } = fetches;
export default {
  name: "results",
  components: {
    MyProgress,
  },
  data() {
    return {
      fileList: [], //图片地址
      srcList: [], //预览图片地址
      studentInfo: {},
      fillresult: {
        state: 1, //是否放弃学位 放弃为0,未放弃为1
        reason: "", //审核不通过或现场确认不通过的原因
        school: "", //选报或调配的学校
        date: "", //审核时间
        lottery: "", //摇号时间
        checkdate: "", //现场确认时间
        status: "0", //审核进度（包含审核摇号及现场确认）
      },
      isSlider: false, //是否可以查看更多图片
      defaultHost: defaultHost,
      password: "password",
      isPwd: false,
      isShowGiveup: false, //是否显示放弃水印
      studTips: {},
      isShowStudTips: false,
      isShowEditBtn: true,
      auditStep: {
        step: 1, // 到达进度
        printIsShow: "", //打印按钮是否展示
        giveUpIsShow: "", //打印按钮是否展示
        auditStatus: "", //预审状态，0表示预审待审或者审核中，Y表示审核通过，N表示审核不通过,F表示放弃就读
        auditStatusName: "", //预审状态名称
        auditReason: "", //预审不通过原因
        schoolName: "", //预录取学校
        schoolStatus: "", //现场审核状态，0代表待审、Y代表审核通过、N代表审核不通过
        schoolStatusName: "", //现场审核状态名称
        schoolReason: "", //现场审核不通过原因
      },
      // verify: {},
    };
  },
  computed: {
    stuList() {
      return this.$store.state.stuList;
    },
    verify() {
      return this.$store.state.verify;
    },
  },
  methods: {
    //是否显示密码
    showPwd() {
      this.isPwd = !this.isPwd;
      // if (this.isPwd) {
      //   this.password = "password";
      // } else {
      //   this.password = "text";
      // }
    },
    //修改学生状态
    updateAudit(status) {
      if (status == "F") {
        Dialog.confirm({
          title: "提示",
          message:
            "放弃学位后本周期不能重报，也不会重新派位，你确定要放弃库尔勒市的学位吗？",
        })
          .then(() => {
            this.$fetch(
              `/api/Student/UpdateRegInfo?auditStatus=${status}`,
              {},
              "post"
            ).then((data) => {
              if (data.res == 0) {
                this.isShowGiveup = true;
                this.isShowStudTips = false;
                this.isShowEditBtn = false;
              } else {
                this.$toast(data.msg);
              }
            });
            // this.isShowGiveup = true;
          })
          .catch(() => {});
      } else {
        this.$fetch(
          `/api/Student/UpdateRegInfo?auditStatus=${status}`,
          {},
          "post"
        ).then((data) => {
          if (data.res == 0) {
            // this.$router.push({
            //   path: "basicinfo",
            //   query: { isEditInfos: "basicinfo" },
            // });
            location.reload();
          } else {
            this.$toast(data.msg);
          }
        });
      }
    },
    //获取结果展示页信息
    getResult() {
      this.$fetch("/api/Student/GetStudResult", "get").then((data) => {
        if (data.res == 0) {
          this.studentInfo = data.data.personAndRegInfo;
          this.studTips = data.data.studTips;
          this.auditStep = data.data.auditStep;

          if (data.data.personAndRegInfo.healthType) {
            if (data.data.personAndRegInfo.healthType == "良好") {
              this.studentInfo.healthType = "良好";
            } else {
              this.studentInfo.healthType = this.studentInfo.disableType;
            }
          }
          if (data.data.personAndRegInfo.houseType) {
            if (data.data.personAndRegInfo.houseType == "1") {
              this.studentInfo.houseType = "父母或本人产权";
            } else if (data.data.personAndRegInfo.houseType == "2") {
              this.studentInfo.houseType = "（外）祖父母产权";
            } else {
              this.studentInfo.houseType = "租住房";
            }
          }

          this.fileList = data.data.regImages;
          //设置图片预览地址
          this.fileList.forEach((val, ind) => {
            val.url = defaultHost + val.imgUrl;
            this.srcList.push(this.defaultHost + val.imgUrl);
          });
          //判断提示信息是否需要弹出显示
          if (this.studTips.studTipsType == 2 && this.studTips.studTips) {
            Dialog.confirm({
              title: "提示",
              message: this.studTips.studTips,
            })
              .then(() => {})
              .catch(() => {});
          } else if (
            this.studTips.studTipsType == 1 &&
            this.studTips.studTips
          ) {
            this.isShowStudTips = true;
          }
        } else {
          this.$toast(data.msg);
        }
      });
    },
    formatDateTime(fmt, mydate) {
      return formatDate(fmt, mydate);
    },
    // 判断学生是否可修改信息、注销
    async getVerify() {
      try {
        const data = await getVerify();
        localDb.set("verify", data);
        this.$store.commit("SETSTVERIFYT", data);
        if (this.verify.res == -1) {
          this.isShowEditBtn = false;
        }
      } catch (error) {}
    },
    //修改
    gotoEdit(type) {
      if (type == "selectgrade") {
        this.$router.push({
          path: "selectgrade",
          query: { isEditInfos: "selectgrade" },
        });
      } else if (type == "basicinfo") {
        this.$router.push({
          path: "basicinfo",
          query: { isEditInfos: "basicinfo" },
        });
      } else if (type == "signup") {
        this.$router.push({
          path: "signup",
          query: { isEditInfos: "signup" },
        });
      }
    },
  },
  created() {
    this.getVerify();
  },
  mounted() {
    this.getResult();
  },
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.reporting-main {
  .iconfont {
    font-size: 38px;
  }
}
.notice-box {
  background-color: #fff;
  padding: 16px 30px;
  color: #ff0000;
  font-size: 26px;
  text-align: justify;
}
.bd {
  position: relative;
  background-color: #f5f5f5;
  .giveup {
    width: 198px;
    height: 209px;
    position: absolute;
    top: 90px;
    right: 20px;
    z-index: 999;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
.result-list {
  margin-bottom: 20px;
  padding: 0 10px;
  .result-list-hd {
    height: 80px;
    line-height: 80px;
    padding: 0 20px;
    text-align: left;
    .title {
      float: left;
      font-size: 36px;
      color: #222;
      span {
        color: #999;
        font-size: 28px;
      }
    }
    .btn-link {
      width: 152px;
      height: 50px;
      border: 1px solid #0195ff;
      float: right;
      font-size: 28px;
      margin-top: 15px;
      line-height: 50px;
      text-align: center;
      border-radius: 6px;
      color: #0195ff;
    }
  }

  .result-list-bd {
    text-align: left;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.1);
    .van-cell {
      padding-left: 5px;
      &.fle {
        /deep/ .van-cell__title {
          flex: 2;
        }
      }
    }
    .list-bd-title {
      height: 72px;
      line-height: 82px;
      padding-left: 34px;
      h3 {
        font-size: 32px;
        font-family: PingFangSC-Semibold;
        position: relative;
        color: #222;
        &::before {
          content: "";
          width: 4px;
          height: 30px;
          background-color: #0195ff;
          position: absolute;
          top: 25px;
          left: -15px;
        }
      }
    }
  }
  .fileList-box {
    padding: 0 0 15px 0;
    font-size: 0;
  }
  .fileList {
    width: 210px;
    height: 210px;
    margin: 15px;
  }
}
.footer-btn {
  padding: 0 50px 30px;
  margin-top: 30px;
  // background: #fff;
  .van-button {
    border-radius: 10px;
  }
}
</style>
<style lang="scss">
.result-list {
  .van-hairline--top-bottom::after {
    border: none;
  }
  .fileList-box {
    .van-uploader {
      width: 100%;
      &.hid {
        width: 100%;
        height: 220px;
        overflow: hidden;
      }
      .van-uploader__wrapper {
        padding: 15px 20px 0;
      }
    }
    .van-uploader__preview-image {
      width: 210px;
      height: 210px;
    }
    .van-uploader__preview {
      margin: 15px 10px;
    }
    .van-uploader__preview-delete {
      display: none;
    }
    .slider {
      margin-top: 20px;
      font-size: 24px;
      text-align: center;
      color: #999;
      .van-icon {
        vertical-align: middle;
      }
    }
  }
}
</style>
